package com.xlh.service.courseTest.impl;

import com.xlh.dao.courseTest.CourseTestPaperAnswerMapper;
import com.xlh.dao.courseTest.CourseTestPaperAnswerMapperExt;
import com.xlh.pojo.courseTest.CourseTestPaperAnswer;
import com.xlh.pojo.courseTest.CourseTestPaperAnswerExample;
import com.xlh.service.courseTest.PaperAnswerService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhr 2019/3/2
 */
@Service
public class PaperAnswerServiceImpl implements PaperAnswerService{
    @Autowired
    private CourseTestPaperAnswerMapperExt mapperExt;
    @Autowired
    private CourseTestPaperAnswerMapper mapper;

    @Override
    public void deleteByPaperId(Long paperId) {
        mapperExt.deleteByPaperId(paperId);
    }

    @Override
    public List<CourseTestPaperAnswer> selectAnswerList(List<Long> questionIds, Long paperId) {
        CourseTestPaperAnswerExample example = new CourseTestPaperAnswerExample();
        example.createCriteria().andQuestionIdIn(questionIds);
        example.setOrderByClause("QUESTION_ID ASC, ORDER_NUMBER ASC");
        List<CourseTestPaperAnswer> result = mapper.selectByExampleWithBLOBs(example);
        if (CollectionUtils.isNotEmpty(result)) {
            result.forEach(answer -> answer.setContent(answer.getHtmlContent()));
        }
        return result;
    }

    @Override
    public Long selectMaxId() {
        return mapperExt.selectMaxId();
    }

    @Override
    public void insertBatch(List<CourseTestPaperAnswer> answerList) {
        mapperExt.insertBatch(answerList);
    }

    @Override
    public void cleanData() {
        mapperExt.cleanData();
    }

}
